<%@ page contentType="application/json; charset=UTF-8" pageEncoding="UTF-8" errorPage="/error.jsp"%>
<%@page import="dbexp.model.Synonym"%>
<%@page import="dbexp.model.db.DbUser"%>
<%@page import="dbexp.connection.DbMetaData"%>
<%@page import="dbexp.connection.DbConnection"%>
<%@page import="org.json.JSONObject"%>
<%
DbUser u = (DbUser)session.getAttribute("USER");
String name = request.getParameter("name");
String schema = request.getParameter("schema");
String action = request.getParameter("action");
String to= request.getParameter("to");
String tn = request.getParameter("tn");

boolean brak = (name==null || name.trim().equals("null")) && (schema==null || schema.trim().equals("null"));
Synonym ob =  new Synonym(name,schema);
if(!brak && action.equals("create")){
	ob.setTableOwner(to);
	ob.setTableName(tn);
	int status = DbMetaData.operateObject(u,ob,DbConnection.CREATE);
}
	ob = DbMetaData.getSynonym(u, name, schema);
out.clearBuffer();%><%=new JSONObject().
													put("success", true).
													put("data",new JSONObject().
															put("name", ob.getName()).
															put("schema",ob.getSchema()).
															put("to",ob.getTableOwner()).
															put("tn",ob.getTableName()).
															put("dbl",ob.getDbLink()))%>